/*
 * Copyright 2009 BioTeam Inc
 * 
 * Licensed under License GNU LESSER GENERAL PUBLIC LICENSE version 3.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.gnu.org/copyleft/lesser.html
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package net.bioteam.appweb.submit;

import java.io.InputStream;

import net.bioteam.appweb.TestConfig;
import net.bioteam.appweb.acd.AcdToProgram;
import net.bioteam.appweb.model.Parameter;
import net.bioteam.appweb.model.Program;
import net.bioteam.appweb.model.ProgramBuilder;
import net.bioteam.appweb.model.XmlToProgram;
import net.sf.ehcache.CacheManager;
import junit.framework.TestCase;

public class BshEvalTest extends TestCase {

	public BshEvalTest(String name) {
		super(name);
	}

	public void setUp() throws Exception {
		TestConfig.init();
		
	}

	public void tearDown() throws Exception {
		TestConfig.shutdown();
	}
	
	public static void main(String args[]) {
		BshEvalTest test = new BshEvalTest("testBeanshellEval");
		junit.textui.TestRunner.run(test);
	}
	public void testBeanshellEval() throws Exception
	{
		Program program;
		Parameter p;
		UnfinishedJob job=new UnfinishedJob();
		job.setWorkdir("D:/workspace/appwebtest");;
		DefaultCommandLineGenerator generator = new DefaultCommandLineGenerator();
		String cmdline, expected;
		ProgramValueBean bean;
		ProgramBuilder.cache.remove("field_beanshell");
		
		program = ProgramBuilder.getProgram("field_beanshell");
		bean = new ProgramValueBean(program);
		
		//input file.
		bean.setValue("seq", "sequence");
		cmdline = generator.generateScript((ProgramValueBean) bean
				.myClone(), job);	
		expected="-seq sequence";
		assertEquals(expected, cmdline.trim());
		
		//string
		bean = new ProgramValueBean(program);
		bean.setValue("seq", "sequence");
		bean.setValue("str", "myStr");
		cmdline = generator.generateScript((ProgramValueBean) bean
				.myClone(), job);	
		expected="-seq sequence";
		assertEquals(expected, cmdline.trim());
		
		bean = new ProgramValueBean(program);
		bean.setValue("seq", "sequence");
		bean.setValue("str", "xxx");
		cmdline = generator.generateScript((ProgramValueBean) bean
				.myClone(), job);	
		expected="-seq sequence  -str xxx";
		assertEquals(expected, cmdline.trim());
		
		bean = new ProgramValueBean(program);
		bean.setValue("seq", "sequence");
		bean.setValue("str", "xxx");
		bean.setValue("str1", "str1");
		cmdline = generator.generateScript((ProgramValueBean) bean
				.myClone(), job);	
		expected="-seq sequence  -str xxx  -str1 str1";
		assertEquals(expected, cmdline.trim());
		
		//integer
		bean = new ProgramValueBean(program);
		bean.setValue("seq", "sequence");
		bean.setValue("aint1", "5");
		bean.setValue("aint", "6");
		cmdline = generator.generateScript((ProgramValueBean) bean
				.myClone(), job);	
		expected="-seq sequence  -aint 5";
		assertEquals(expected, cmdline.trim());
		
		bean = new ProgramValueBean(program);
		bean.setValue("seq", "sequence");
		bean.setValue("aint1", "5");
		bean.setValue("aint", "7");
		cmdline = generator.generateScript((ProgramValueBean) bean
				.myClone(), job);	
		expected="-seq sequence  -aint 7  -aint 5";
		assertEquals(expected, cmdline.trim());
		
		//float
		bean = new ProgramValueBean(program);
		bean.setValue("seq", "sequence");
		bean.setValue("afloat", "6.4");
		bean.setValue("afloat1", "6.1");
		cmdline = generator.generateScript((ProgramValueBean) bean
				.myClone(), job);	
		expected="-seq sequence  -float1 6.1";
		assertEquals(expected, cmdline.trim());
		
		bean = new ProgramValueBean(program);
		bean.setValue("seq", "sequence");
		bean.setValue("afloat", "6.6");
		bean.setValue("afloat1", "6.1");
		cmdline = generator.generateScript((ProgramValueBean) bean
				.myClone(), job);	
		expected="-seq sequence  -float 6.6  -float1 6.1";
		assertEquals(expected, cmdline.trim());
		
		
		//switch
		bean = new ProgramValueBean(program);
		bean.setValue("seq", "sequence");
		bean.setValue("aswitch", "0");
		bean.setValue("bswitch", "0");
		cmdline = generator.generateScript((ProgramValueBean) bean
				.myClone(), job);	
		expected="-seq sequence  -bswitch";
		assertEquals(expected, cmdline.trim());
		
		bean = new ProgramValueBean(program);
		bean.setValue("seq", "sequence");
		bean.setValue("aswitch", "1");
		bean.setValue("bswitch", "1");
		cmdline = generator.generateScript((ProgramValueBean) bean
				.myClone(), job);	
		expected="-seq sequence  -aswitch";
		assertEquals(expected, cmdline.trim());
		
		
		
	}

}
